<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员登录</title>

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<style>
    .middle{
        position: relative;
        top: 50%;
        transform: translateY(-90%);
    }
</style>
<body>
    <div class="vh-100">
        <form class='w-50 m-auto middle'>
            <div class="form-group">
            <label for="loginUser">账号</label>
            <input type="text"  class="form-control" id="loginUser" aria-describedby="emailHelp">
            <!-- <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> -->
            </div>
            <div class="form-group">
            <label for="loginPasswd">密码</label>
            <input type="password" class="form-control" id="loginPasswd">
            </div>
            <div class="form-group form-check">
            <!-- <input type="checkbox" class="form-check-input" id="exampleCheck1"> -->
            <!-- <label class="form-check-label" for="exampleCheck1">保存到本地</label> -->
            </div>
            <span id="loginBtn" class="btn btn-primary float-right">登录</span>
        </form>
    </div>



    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->

    <script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    <script src="/js/axios.min.js"></script>
    <script>
        if(localStorage.getItem('admin_token')){
            localStorage.removeItem('admin_token')
        }
        $('#loginBtn').on('click',function(){
            axios.post('/api/admin/login',{username:$('#loginUser')[0].value,password: $('#loginPasswd')[0].value})
            .then(function(res){
                if(res.data.error){
                    alert(res.data.error)
                }else{
                    localStorage.setItem('admin_token',res.data.token)
                    location.href = '/admin'
                }
            })
            return false;
        })
    </script>
</body>
</html>
